package org.ymjava.medical.db.AllPackage.biz;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.ymjava.medical.db.AbstractBaseBiz.BaseBiz;
import org.ymjava.medical.db.AllPackage.entity.SysRole;
import org.ymjava.medical.db.AllPackage.mapper.SysRoleMapper;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 角色表
 *
 * @author zhy
 * @email ${email}
 * @date 2020-04-03 15:53:44
 */
@Service
public class SysRoleBiz extends BaseBiz<SysRoleMapper,SysRole> {

	@Resource
	private SysRoleMapper sysRoleMapper;

	public List<Map> getUserRole(String uesrId) {
		return sysRoleMapper.getUserRole(uesrId);
	}

	public List<SysRole> queryByRname(String rname){
		Example example = new Example(SysRole.class);
		example.or().andEqualTo("rname",rname);
		return sysRoleMapper.selectByExample(example);
	}

	public Map<String,Object> queryAll(String rname,Integer page, Integer size, String sort, String order){
		Example example = new Example(SysRole.class);
		if(StringUtils.isNotBlank(rname)){
			example.createCriteria().andLike("rname",rname);
		}
		Page<Object> result = PageHelper.startPage(page, size);
		sysRoleMapper.selectByExample (example);
		Map<String,Object> map = new HashMap<>();
		map.put("total",result.getTotal());
		map.put("items",result.getResult());
		return map;
	}
}